package com.liuxy.androidutil;

import com.liuxy.javautil.IOUtil;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;

public class UriUtil {
	private static final String TAG = "MyTools.UriUtil";
	
	public String getAbsoluteImagePath(Context ctx, Uri uri) {
		String[] proj = { MediaStore.Images.Media.DATA };
		Cursor cursor = ctx.getContentResolver().query(uri, 
				proj, // Which columns to return
				null, // WHERE clause; which rows to return (all rows)
				null, // WHERE clause selection arguments (none)
				null); // Order-by clause (ascending by name)
		try {
			int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
			cursor.moveToFirst();
			return cursor.getString(column_index);
		}finally {
			IOUtil.close(cursor);
		}
	}
	
	private UriUtil(){
		/* cannot be instantiated */
		throw new UnsupportedOperationException(TAG+" cannot be instantiated");
	}
}
